from google.appengine.ext import db

# Create your models here.

class Language(db.Model):
  name = db.StringProperty()
  tla = db.StringProperty()
  iso = db.StringProperty()

  def __str__(self):
    return '%s' %self.name

class POS(db.Model):
  value = db.StringProperty()

  def __str__(self):
    return '%s' %self.value

  def get_absolute_url(self):
    return '/help/%s/' % self.key()

class Entry(db.Model):
  value = db.StringProperty()
  added_on = db.DateTimeProperty(auto_now_add=True)
  lang = db.ReferenceProperty(Language)
  
  def get_absolute_url(self):
    return '/entry/%s/' % self.key()

  def get_translations(self):
    return Translation.all().filter('entry = ', self)

class Translation(db.Model):
  pos = db.ReferenceProperty(POS)
  entry = db.ReferenceProperty(Entry)
  value = db.StringProperty()
  # Note for speakers of source language
  src_note = db.StringProperty()
  # Note for speaker of target language
  target_note = db.StringProperty()

  # meta attributes
  added_on = db.DateTimeProperty(auto_now_add=True)

  def get_examples(self):
    return Example.all().filter('translation = ', self)

  def __str__(self):
    return '%s' %self.value

  def get_absolute_url(self):
    return '/translation/%s/' % self.key()

  def get_pos(self):
    return POS.get(self.pos.key())

class Example(db.Model):
  translation = db.ReferenceProperty(Translation)
  src_example = db.StringProperty()
  target_example = db.StringProperty()
  added_on = db.DateTimeProperty(auto_now_add=True)

  def __str__(self):
    return '%s' %self.source_example

  def get_absolute_url(self):
    return '/example/%s/' % self.key()
